package com.example.wenliangjiudian.config;

import com.example.wenliangjiudian.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("进入拦截规则");

        //拦截所有访问请求,必须用户登录后才可访问,
        //但是这样拦截的路径中有一些是不需要用户登录也可访问的
        String[] addPathPatterns = {
                "/**",
        };

        //要排除的路径,排除的路径说明不需要用户登录也可访问
        String[] excludePathPatterns = {
                "/",
                "/404",
                "/error",
                "/user/login",
                "/user/registerBtn",
                "/user/register",
                "/root/quit",
                "/menu/getMyMenu",
                "/css/**",
                "/js/**",
                "/img/**",
                "/data/**"
        };
        //excludePathPatterns = addContextPath(excludePathPatterns);
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }

}
